const CryptoJs = require('crypto');

const key = '1111222233334444' //16位十六进制作为密钥
const iv = 'ABCDEF1234123412' //偏移量

function Encrypt(data) {
  var cipherChunks = [];
  var cipher = CryptoJs.createCipheriv('aes-128-cbc', key, iv);
  cipher.setAutoPadding(true);
  cipherChunks.push(cipher.update(data, 'utf8', 'base64'));
  cipherChunks.push(cipher.final('base64'));
  return cipherChunks.join('');
};


function Decrypt(data) {
  let cipherChunks = [];
  let decipher = CryptoJs.createDecipheriv('aes-128-cbc', key, iv);
  decipher.setAutoPadding(true);
  cipherChunks.push(decipher.update(data, 'base64', 'utf8'));
  cipherChunks.push(decipher.final('utf8'));
  return cipherChunks.join('');
}

module.exports = {
  Encrypt,
  Decrypt
}